package com.ruoyi.web.controller.scrap;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.scrap.domain.ScrapApply;
import com.ruoyi.scrap.domain.po.ScrapApplyPo;
import com.ruoyi.scrap.domain.vo.ScrapApplyAuditVo;
import com.ruoyi.scrap.domain.vo.ScrapApplyVo;
import com.ruoyi.scrap.service.ScrapApplyInfoService;
import com.ruoyi.scrap.service.ScrapApplyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/scrap/apply")
public class ScrapApplyController extends BaseController {

    @Resource
    ScrapApplyService applyService;

    @Resource
    ScrapApplyInfoService applyInfoService;

    @GetMapping("/list")
    public TableDataInfo list(ScrapApplyPo apply)
    {
        startPage();
        List<ScrapApplyPo> list = applyInfoService.getScrapApplyInfo(apply);
        return getDataTable(list);
    }

    @Log(title = "报废物资处置申请单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrapApplyPo apply)
    {
        List<ScrapApplyPo> list = applyInfoService.getScrapApplyInfo(apply);
        ExcelUtil<ScrapApplyPo> util = new ExcelUtil<ScrapApplyPo>(ScrapApplyPo.class);
        util.exportExcel(response, list, "sheet1","报废物资处置申请表");
    }

    @GetMapping(value = "/info/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(applyService.getInfo(id));
    }

    @Log(title = "报废物资处置申请单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ScrapApplyVo apply) {
        return toAjax(applyService.save(apply,getLoginUser().getUser()));
    }

    @Log(title = "报废入库记录单", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(applyService.remove(ids,getLoginUser().getUser()));
    }

    @GetMapping("/auditor")
    public AjaxResult auditor() {
        return AjaxResult.success(applyService.auditor(getLoginUser().getUser()));
    }

}
